// 燃气类型占比/排行
var numberFormate = iot.getNumberFormat("0.00");
dev.action = function(resp,param){
    //获取工厂名称
    var factoryName = getFactoryName(param.workSpaceName);
    //是否算总还是单
    var totalOrSingle = param.selectType;
    if (totalOrSingle == null){
        totalOrSingle = "total";
    }
    var theTime = param.time;
    var workSpace = param.workSpace;
    var datas =  iot.list();
    var legend =  iot.list();
    var db = iot.db();
    var result = db.qry("select SUM(dev_win.dvalue) totalSum from iot_dev_data_win dev_win," +
        " (select dev_id, name from energy_struc_prop where type = 1 and field_type = '用量' and energy_struc_id = "+ workSpace +") esp" +
        " where dev_win.dev_id = esp.dev_id and dev_win.data_type = esp.name" +
        " and dev_win.the_time like '"+ theTime +"%'");
    //获取产量
    var yieldId = getFactoryYieldId(factoryName)

    var yieldResult = getFactoryYield(yieldId, theTime)

    var totalYield = yieldResult.totalSum;
    var totalUseNum = 0;
    result.forAll(function (item) {
        if (item && item.totalSum) {
            totalUseNum = item.totalSum;
        }
    })


    //判断当前选择总数还是单车
    if (totalOrSingle.equals("total")) {
        datas.add({name: "总燃气", value: numberFormate.format(totalUseNum)});
        legend.add("总燃气");
    }else if (totalOrSingle.equals("single")) {
        if (totalYield){
            totalUseNum = totalUseNum/totalYield;
        }
        legend.add("单车燃气");
        datas.add({name: "单车燃气", value: numberFormate.format(totalYield === null ? 0 : totalUseNum)});
    }
    var jsData = {
        datas : datas,
        legend : legend
    };
    resp.setJsData(jsData);
}